package com.snail.billing.page.view;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.util.ResUtil;
import com.snail.billing.Resource;

public class UserCenterAdapter extends BaseAdapter {

	private List<AdapterData> data;

	public UserCenterAdapter(List<AdapterData> data) {
		this.data = data;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(ResUtil.getLayoutId(Resource.layout.snailbilling_user_center_item), null, false);
		}
		ImageView imageView = (ImageView) convertView.findViewById(ResUtil.getViewId(Resource.id.snailbilling_user_center_item_image));
		TextView textView = (TextView) convertView.findViewById(ResUtil.getViewId(Resource.id.snailbilling_user_center_item_text));
		TextView textView2 = (TextView) convertView.findViewById(ResUtil.getViewId(Resource.id.snailbilling_user_center_item_text2));
		//
		AdapterData adapterData = (AdapterData) getItem(position);
		imageView.setImageResource(adapterData.imageId);
		textView.setText(adapterData.textId);
		if (adapterData.text2 != null) {
			textView2.setText(adapterData.text2);
		} else {
			textView2.setText("");
		}
		return convertView;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public static class AdapterData {

		public AdapterData(int imageId, int textId) {
			this.imageId = imageId;
			this.textId = textId;
		}

		public int imageId;
		public int textId;
		public String text2;
	}

}